package com.example.blankapp;

import java.net.URI;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.net.*;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import tool.tools;
import android.location.*;
import android.net.http.*;
import org.apache.http.client.*;
import org.apache.http.client.ResponseHandler;

public class MainActivity extends Activity {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_main);
        Button button_add = (Button)findViewById(R.id.ADD);
        final Button button_loc = (Button)findViewById(R.id.loc);
        final TextView text1=(TextView)findViewById(R.id.Loc_info);
        EditText additem=(EditText)findViewById(R.id.item);
        final TextView result=(TextView)findViewById(R.id.info);
        ArrayAdapter<String> adapter;
        android.net.wifi.WifiInfo wifi;
        button_add.setOnClickListener(new OnClickListener(){
        
			@Override
			public void onClick(View v) {
				if(tools.isNetworkConnected(getApplicationContext()))
                {
					Toast.makeText
					(getApplicationContext(), "connected", Toast.LENGTH_SHORT).show();
                    String url="http://www.baidu.com/";
                    HttpClient hc=new DefaultHttpClient();
                    HttpGet hg=new HttpGet(url);
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                    try {
                        String res;
                        res = hc.execute(hg,responseHandler);
                        result.setText(res);



                    }
                    catch (Exception e)
                    {
                        result.setText("error");
                    }



                }
				else
					Toast.makeText
					(getApplicationContext(),"not connected", Toast.LENGTH_SHORT).show();
			}
			
        });
        button_loc.setOnClickListener(new OnClickListener(){

			private List<String> info;

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				LocationManager man=
						(LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
				info = man.getAllProviders();
				text1.setText(info.get(0));
				
			}
        	
        });
			
    }
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
    	switch(item.getItemId())
    	{
    		case R.id.exit:
    			Toast.makeText(getApplicationContext(), "exit", Toast.LENGTH_SHORT).show();
    			break;
    		case R.id.action_settings:
    			Toast.makeText(getApplicationContext(), "settings", Toast.LENGTH_SHORT).show();
    			break;
    		default:
    			break;
    	}
		return false;
    	
    }
}
